<?php
//引入文件
include_once ("pdo.php");
//实例化
$obj=new Me("root","root");
//接收数据
$name=$_POST['user_name'];
$pwd=$_POST['user_pwd'];
//验证用户名
$preg_name="/^[0-9|a-Z]{5,20}$/";
if (!preg_match($preg_name,$name) || $name=='') {
    echo "<script>alert('用户名不能为空且只能是数组或字母组合');location.href='login.php'</script>";
}
//验证密码
$preg_pwd="/^[0-9|a-Z]{6,20}$/";
if (!preg_match($preg_pwd,$pwd) || $pwd=='') {
    echo "<script>alert('密码不能为空且为字符，数字与符号两种以上组成');location.href='login.php'</script>";
}
//查询数据
$data=$obj->getOne("user","user_name='$name' and user_pwd='$pwd'");
//判断
if($data){
    session_start();
    $p=$_SESSION=$name;
    if(!isset($p)){
        echo "<script>alert('请先登录');location.href='login.php'</script>";
    }else{
        echo "<script>alert('登录成功');location.href='add.php'</script>";
    }

}else{
    echo "<script>alert('登录失败');location.href='login.php'</script>";
}


